﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Media;
namespace Gronia.WPF.Controls
{
    public partial class CameraPanel : Panel
    {
        public static readonly DependencyProperty XProperty = DependencyProperty.RegisterAttached("X", typeof(double), typeof(CameraPanel), new UIPropertyMetadata(0.0, new PropertyChangedCallback(InvalidateArrange)));
        public static readonly DependencyProperty YProperty = DependencyProperty.RegisterAttached("Y", typeof(double), typeof(CameraPanel), new UIPropertyMetadata(0.0, new PropertyChangedCallback(InvalidateArrange)));
        public static readonly DependencyProperty ZProperty = DependencyProperty.RegisterAttached("Z", typeof(double), typeof(CameraPanel), new UIPropertyMetadata(0.0, new PropertyChangedCallback(InvalidateArrange)));
        private static readonly DependencyProperty ScaleTransformProperty = DependencyProperty.RegisterAttached("ChildScaleTransform", typeof(Transform), typeof(CameraPanel), new UIPropertyMetadata(null));
        public static readonly DependencyProperty CameraXProperty = DependencyProperty.Register("CameraX", typeof(double), typeof(CameraPanel), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsMeasure));
        public static readonly DependencyProperty CameraYProperty = DependencyProperty.Register("CameraY", typeof(double), typeof(CameraPanel), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsMeasure));
        public static readonly DependencyProperty CameraZProperty = DependencyProperty.Register("CameraZ", typeof(double), typeof(CameraPanel), new FrameworkPropertyMetadata(-5.0, FrameworkPropertyMetadataOptions.AffectsMeasure));
        public static readonly DependencyProperty ZScaleFactorProperty = DependencyProperty.Register("ZScaleFactor", typeof(double), typeof(CameraPanel), new FrameworkPropertyMetadata(300.0, FrameworkPropertyMetadataOptions.AffectsMeasure));

        public double CameraX
        {
            get
            {
                return (double)base.GetValue(CameraXProperty);
            }
            set
            {
                base.SetValue(CameraXProperty, value);
            }
        }
        public double CameraY
        {
            get
            {
                return (double)base.GetValue(CameraYProperty);
            }
            set
            {
                base.SetValue(CameraYProperty, value);
            }
        }
        public double CameraZ
        {
            get
            {
                return (double)base.GetValue(CameraZProperty);
            }
            set
            {
                base.SetValue(CameraZProperty, value);
            }
        }
        public double ZScaleFactor
        {
            get
            {
                return (double)base.GetValue(ZScaleFactorProperty);
            }
            set
            {
                base.SetValue(ZScaleFactorProperty, value);
            }
        }

        public static double GetX(DependencyObject obj)
        {
            return (double)obj.GetValue(XProperty);
        }
        public static void SetX(DependencyObject obj, double value)
        {
            obj.SetValue(XProperty, value);
        }
        public static double GetY(DependencyObject obj)
        {
            return (double)obj.GetValue(YProperty);
        }
        public static void SetY(DependencyObject obj, double value)
        {
            obj.SetValue(YProperty, value);
        }
        public static double GetZ(DependencyObject obj)
        {
            return (double)obj.GetValue(ZProperty);
        }
        public static void SetZ(DependencyObject obj, double value)
        {
            obj.SetValue(ZProperty, value);
        }
        private static Transform GetScaleTransform(DependencyObject obj)
        {
            return (Transform)obj.GetValue(ScaleTransformProperty);
        }
        private static void SetScaleTransform(DependencyObject obj, Transform value)
        {
            obj.SetValue(ScaleTransformProperty, value);
        }

        private static void InvalidateArrange(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            CameraPanel panel = VisualTreeHelper.GetParent(sender) as CameraPanel;
            panel.InvalidateArrange();
        }
    }
}